﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DbAdapter.sqldbAdapter;

namespace Water.Model
{
    /// <summary>
    /// 水表
    /// </summary>
    public class Meter
    {
        public virtual string METERID { get; set; }
        public virtual string CUSTID { get; set; }
        public virtual string CUSTNAME { get; set; }
        public virtual string MEASURE { get; set; }
        public virtual string PIPEID { get; set; }
        public virtual string LOCATION { get; set; }
        public virtual string ROADNAME { get; set; }
        public virtual DateTime DATEI { get; set; }
        public virtual double INLETD { get; set; }
        public virtual double METERD { get; set; }
        public virtual string TYPE { get; set; }
        public virtual double INLETNUM { get; set; }
        public virtual double MAXDURATION { get; set; }
        public virtual string CONTACT { get; set; }
        public virtual string OFFDAY { get; set; }
        public virtual double PHONE { get; set; }
        public virtual string METERTYPE { get; set; }
        public virtual DateTime CALIBRATEDAT { get; set; }
        public virtual DateTime REPLACINGDATE { get; set; }
        public virtual double USAGEQ { get; set; }
        public virtual string DEPTH { get; set; }
        public virtual string PAVEMENT { get; set; }
        public virtual string YSLB { get; set; }
        public virtual double GPS { get; set; }
        public virtual double ELEV { get; set; }
        public virtual string KH { get; set; }
        public virtual string PROJECT { get; set; }
        public virtual string SOURCE { get; set; }
        public virtual string SBLB { get; set; }
        public virtual int GJZ { get; set; }
        public virtual string PICTURE { get; set; }
        public virtual string SSQX { get; set; }
        public virtual string SSZS { get; set; }
        public virtual string TFH { get; set; }
        public virtual string MEMO { get; set; }
        public virtual string EpcNO { get; set; }

        /// <summary>
        /// 根据epcno获取水表信息
        /// </summary>
        /// <param name="epcno"></param>
        /// <returns></returns>
        public IList<Meter> GetMeterByEpcNo(string epcno)
        {
            string sql = "select * from TZ_FJMYHSB where EpcNo = '" + epcno + "'";
            sqldb db = new sqldb();
            DataSet ds = db.ExecuteDataset(sqlconn.GetConnStr(),CommandType.Text,sql);
            IList<Meter> mrlist = null;
            if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                mrlist = new List<Meter>();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    Meter objmenu = new Meter();

                    objmenu.CUSTID = dr["CUST_ID"].ToString();
                    objmenu.CUSTNAME = dr["CUST_NAME"].ToString();
                    objmenu.METERID = dr["METER_ID"].ToString();
                    objmenu.MEASURE = dr["MEASURE"].ToString();
                    objmenu.PIPEID = dr["PIPE_ID"].ToString();
                    objmenu.LOCATION = dr["LOCATION"].ToString();
                    objmenu.ROADNAME = dr["ROADNAME"].ToString();
                    objmenu.DATEI = Convert.ToDateTime(dr["DATE_I"]);
                    objmenu.INLETD = Convert.ToDouble(dr["INLET_D"]);
                    objmenu.METERD = Convert.ToDouble(dr["METER_D"]);
                    objmenu.TYPE = dr["TYPE"].ToString();
                    objmenu.INLETNUM = Convert.ToDouble(dr["INLET_NUM"]);
                    objmenu.MAXDURATION = Convert.ToDouble(dr["MAX_DURATION"]);
                    objmenu.CONTACT = dr["CONTACT"].ToString();
                    objmenu.OFFDAY = dr["OFF_DAY"].ToString();
                    objmenu.PHONE = Convert.ToDouble(dr["PHONE"]);
                    objmenu.METERTYPE = dr["METER_TYPE"].ToString();
                    objmenu.CALIBRATEDAT = Convert.ToDateTime(dr["CALIBRATE_DAT"]);
                    objmenu.REPLACINGDATE = Convert.ToDateTime(dr["REPLACING_DATE"]);
                    objmenu.USAGEQ = Convert.ToDouble(dr["USAGE_Q"]);
                    objmenu.DEPTH = dr["DEPTH"].ToString();
                    objmenu.PAVEMENT = dr["PAVEMENT"].ToString();
                    objmenu.YSLB = dr["YSLB"].ToString();
                    objmenu.GPS = Convert.ToDouble(dr["GPS"]);
                    objmenu.ELEV = Convert.ToDouble(dr["ELEV"]);
                    objmenu.KH = dr["KH"].ToString();
                    objmenu.PROJECT = dr["PROJECT"].ToString();
                    objmenu.SOURCE = dr["SOURCE"].ToString();
                    objmenu.SBLB = dr["SBLB"].ToString();
                    objmenu.GJZ = Convert.ToInt32(dr["GJZ"]);
                    objmenu.PICTURE = dr["PICTURE"].ToString();
                    objmenu.SSQX = dr["SSQX"].ToString();
                    objmenu.SSZS = dr["SSZS"].ToString();
                    objmenu.TFH = dr["TFH"].ToString();
                    objmenu.MEMO = dr["MEMO"].ToString();
                    objmenu.EpcNO = dr["EpcNO"].ToString();
                    mrlist.Add(objmenu);
                }
            }
            return mrlist;           
        }
    }
}
